package com.servlet;

import com.dao.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/DeleteServlet")
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            deleteCode(req,resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            deleteCode(req,resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //删除
    private void deleteCode(HttpServletRequest req, HttpServletResponse resp) throws SQLException, ServletException, IOException {
        Integer sid = Integer.parseInt(req.getParameter("sid"));
        System.out.println(sid+"11");
            Student student = new Student();
            student.deleteData(sid);
            req.getRequestDispatcher("check").forward(req,resp);

    }
}
